import { Dispatch } from 'react';
import store from '@/stores/redux';
const initState = {
	count: 0,
	token: '',
	name: ''
};
export const setToken = (val: string) => {
	return (dispatch: Dispatch<any>) => {
		setTimeout(() => {
			dispatch({ type: 'SET_TOKEN', token: val });
		}, 5000);
	};
};

// export const setCount = (val: string | number) => {
// 	console.log(12399,'--',val)
// 	return (dispatch: Dispatch<any>) => {
// 		setTimeout(() => {
// 			console.log(123)
// 			dispatch({ type: 'SET_COUNT', count: val });
// 		}, 1000);
// 	};
// };
export const setCount = (val: string | number) => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			store.dispatch({ type: 'SET_COUNT', count: val });
			resolve('success');
		}, 1000);
	});
};

export const Info = (state = initState, action: any) => {
	switch (action.type) {
		case 'SET_TOKEN':
			return { ...state, token: action.token };
		case 'SET_COUNT':
			return { ...state, count: action.count };
		default:
			return state;
	}
};
